/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ch3;

import java.awt.Color;
import java.text.DateFormatSymbols;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;

/**
 *
 * @author Administrator
 */
@ManagedBean(name = "form")
@SessionScoped
public class FormBean {

    /**
     * Creates a new instance of FormBean
     */
    public FormBean() {
    }

    public enum Education {

        高中, 大学, 研究生
    };

    private String name;
    private boolean contactMe;
    private String[] lovestyle;
    private Integer yearOfBirth;

    public String[] getLovestyle() {
        return lovestyle;
    }

    public void setLovestyle(String[] ltyle) {
        int size = ltyle.length;
        lovestyle = new String[size];
        for (int i = 0; i < size; i++) {
            lovestyle[i] = ltyle[i];
        }

    }
    private int[] colors;

    public Set<String> getCars() {
        return cars;
    }

    public void setCars(Set<String> cars) {
        this.cars = cars;
    }
    private Set<String> cars = new TreeSet<String>();
    private Education education = Education.大学;

    public String getName() {
        return name;
    }

    public void setName(String newValue) {
        name = newValue;
    }

    public boolean getContactMe() {
        return contactMe;
    }

    public void setContactMe(boolean newValue) {
        contactMe = newValue;
    }

    public Integer getYearOfBirth() {
        return yearOfBirth;
    }

    public void setYearOfBirth(Integer newValue) {
        yearOfBirth = newValue;
    }

    public int[] getColors() {
        return colors;
    }

    public void setColors(int[] newValue) {
        colors = newValue;
    }

    public Education getEducation() {
        return education;
    }

    public void setEducation(Education newValue) {
        education = newValue;
    }

    public Collection<SelectItem> getYearItems() {
        return birthYears;
    }

    public String[] getCarStyles() {
        return stylenames;
    }

    public SelectItem[] getCarItems() {
        return carItems;
    }

    public SelectItem[] getColorItems() {
        return colorItems;
    }

    public Map<String, Education> getEducationItems() {
        return educationItems;
    }

    public String getCarStyleConcatenated() {
       // return Arrays.toString(lovestyle);
        StringBuilder result = new StringBuilder();
        for (String s : lovestyle) {
            result.append(s+" ");
        }
        return result.toString();
    }

    public String getColorsConcatenated() {
        StringBuilder result = new StringBuilder();
        for (int color : colors) {
            result.append(String.format("%06x ", color));
        }
        return result.toString();
    }
    private SelectItem[] colorItems = {
        new SelectItem(Color.RED.getRGB(), "红"), // value, label
        new SelectItem(Color.GREEN.getRGB(), "绿"),
        new SelectItem(Color.BLUE.getRGB(), "蓝"),
        new SelectItem(Color.YELLOW.getRGB(), "黄"),
        new SelectItem(Color.BLACK.getRGB(), "黑", "", true) // disabled
    };
    private static Map<String, Education> educationItems;

    static {
        educationItems = new LinkedHashMap<String, Education>();
        educationItems.put("高中", Education.高中); // label, value
        educationItems.put("大学", Education.大学);
        educationItems.put("研究生", Education.研究生);

    }
    ;

   private static SelectItem[] carItems = {
        new SelectItem("Benz"),
        new SelectItem("BMW"),
        new SelectItem("Audi"),
        new SelectItem("Buick"),
        new SelectItem("Jeep"),};
    private static Collection<SelectItem> birthYears;

    static {
        birthYears = new ArrayList<SelectItem>();
        // The first item is a "no selection" item
        birthYears.add(new SelectItem(null, "选择一个年份", "", false, false, true));
        for (int i = 1950; i < 2012; ++i) {
            birthYears.add(new SelectItem(i));
        }
    }
    private static String[] stylenames = {"跑车", "轿车", "越野车", "旅行车", "皮卡", "MPV", "面包车"};
}
